--ProgressUI.lua
require 'fairygui.Window'

local mfloor = math.floor


ProgressUI = class(Window)
local prop = property(ProgressUI)
prop:accessor("progress", nil)
prop:accessor("title", nil)

function ProgressUI:__init()
    g_event_mgr:addListener(self, "onLoadingData")
    self:loadLayout("ProgressUI", "Main")
end

function ProgressUI:initEvent()
    self.title = self:getChild("title");
    self.progress = self:getChild("progress");
end

function ProgressUI:initComponent()
    self.progress.value = 0
    self.title.text = "0%"
end

function ProgressUI:onLoadingData(max, cur)
    local val = mfloor((cur / max) * 100)
    self.title.text = val.."%"
    self.progress.value = val
end

function ProgressUI:show()
    self:open()
end

function ProgressUI:done()
    self.progress.value = 100
    self.title.text = "100%"
    self:close()
end

function ProgressUI:onClose()
end